<!DOCTYPE html>
<html xmlns:th="http://www.springframework.org/schema/data/jaxb">
<head>
    <meta charset="UTF-8">
    <title>添加文章</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" th:href="@{../lib/layui/css/layui.css}">
    <link rel="stylesheet" th:href="@{../css/okadmin.css}">
    <link rel="stylesheet" th:href="@{../css/popwin.css}">
    <link rel="stylesheet" th:href="@{../font/iconfont.css}">
</head>
<body>
<div class="ok-body">
    <!--form表单-->
    <form class="layui-form layui-form-pane ok-form">
        <table style="width:100%;">
            <tr>
                <td width="40%">
                    <div class="layui-form-item">
                        <label class="layui-form-label">公司名称</label>
                        <div class="layui-input-block">
                            <input type="text" th:value="${company.name}" name="name" placeholder="名称" autocomplete="off" class="layui-input" lay-verify="required">
                        </div>
                    </div>
                </td>
                <td rowspan="4">
                    <div class="layui-form-item">
                        <div class="layui-input-block" style="margin-left: 0px;text-align: center;">
                            <img th:src="@{../imgs/upload.png}" title="logo" id="handSignImage" style="height:100px;right:10px; cursor:pointer;border:#E5E5E5 1px solid;border-radius:5px;" />
                            <input type="hidden" th:value="${company.logo}" name="logo" id="logo">
                        </div>
                    </div>
                </td>
            </tr>
            <tr>
                <td>
                    <div class="layui-form-item">
                        <label class="layui-form-label">英文名</label>
                        <div class="layui-input-block">
                            <input type="text" th:value="${company.enName}" name="enName" placeholder="英文名" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </td>
            </tr>
            <tr>
                <td>
                    <div class="layui-form-item">
                        <label class="layui-form-label">中文简称</label>
                        <div class="layui-input-block">
                            <input type="text" th:value="${company.sname}" name="sname" placeholder="简称" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </td>
            </tr>
            <tr>
                <td>
                    <div class="layui-form-item">
                        <label class="layui-form-label">英文简称</label>
                        <div class="layui-input-block">
                            <input type="text" th:value="${company.senName}" name="senName" placeholder="简称" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </td>
            </tr>
            <tr>
                <td>
                    <div class="layui-form-item">
                        <label class="layui-form-label">联系地址</label>
                        <div class="layui-input-block">
                            <input type="text" th:value="${company.address}" name="address" placeholder="地址" autocomplete="off" class="layui-input" lay-verify="required">
                        </div>
                    </div>
                </td>
                <td>
                    <div class="layui-form-item">
                        <label class="layui-form-label">邮箱地址</label>
                        <div class="layui-input-block">
                            <input type="text" th:value="${company.mail}" name="mail" placeholder="邮箱" autocomplete="off" class="layui-input" lay-verify="required">
                        </div>
                    </div>
                </td>
            </tr>
            <tr>
                <td>
                    <div class="layui-form-item">
                        <label class="layui-form-label">固定电话</label>
                        <div class="layui-input-block">
                            <input type="text" th:value="${company.phone1}" name="phone1" placeholder="电话" autocomplete="off" class="layui-input" lay-verify="required">
                        </div>
                    </div>
                </td>
                <td>
                    <div class="layui-form-item">
                        <label class="layui-form-label">移动电话</label>
                        <div class="layui-input-block">
                            <input type="text" th:value="${company.phone2}" name="phone2" placeholder="电话" autocomplete="off" class="layui-input" lay-verify="required">
                        </div>
                    </div>
                </td>
            </tr>
            <tr>
                <td>
                    <div class="layui-form-item">
                        <label class="layui-form-label">ICP备案</label>
                        <div class="layui-input-block">
                            <input type="text" th:value="${company.icpNumber}" name="icpNumber" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </td>
                <td>
                    <div class="layui-form-item">
                        <label class="layui-form-label">介绍文章</label>
                        <div class="layui-input-block">
                            <input type="text" th:value="${company.description}" name="description" readonly="readonly" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </td>
            </tr>
        </table>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">公司简介</label>
            <div class="layui-input-block">
                <textarea name="introduce" th:text="${company.introduce}" placeholder="简介" class="layui-textarea" lay-verify="required"></textarea>
            </div>
        </div>
        <div class="popwin-footer">
                <button class="layui-btn" lay-submit lay-filter="add">保存</button>
        </div>
    </form>
</div>
<script th:src="@{../lib/layui/layui.all.js}"></script>
<script>
    layui.use(['element', 'form', 'jquery', 'laydate'], function () {
        var form = layui.form;
        var $ = layui.jquery;

        if($("#logo").val()){
            $("#handSignImage").prop("src", $("#logo").val());
        }

        form.on('submit(add)', function (data) {
            $.ajax({
                url: "update",
                method: "post",
                data: data.field,
                dataType: "json",
                success: function (result) {
                    if (result.success) {
                        layer.msg("修改成功", function () {
                            location.reload();
                        });
                    } else {
                        layer.msg(result.msg == null ? "添加失败" : result.msg, {icon: 6, time: 1000, anim: 4});
                    }
                }, error: function () {
                    layer.msg("添加失败, 稍后重试.", {icon: 6, time: 1000, anim: 4});
                }
            });
            return false;
        });

        layui.upload.render({
            elem: '#handSignImage'
            ,url: '../attachment/uploadImgWithoutInsert'
            ,auto: true //选择文件后自动上传
            ,accept: 'image/*'
            ,field: 'file'
            ,size:20480 //KB
            ,multiple: false
            ,done: function(res, index, upload){ //上传后的回调
                $("#logo").val(res.obj.location);
                $("#handSignImage").prop("src", res.obj.location);
            }
        })
    })
</script>
</body>
</html>
